package com.yuan.dao;

import com.yuan.entity.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;

@Repository
public class TestDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public Test getById(Integer id) {
        return jdbcTemplate.queryForObject("select * from test where id=?", new RowMapper<Test>() {
            @Override
            public Test mapRow(ResultSet resultSet, int i) throws SQLException {
                Test test = new Test();
                test.setId(resultSet.getInt("id"));
                return test;
            }
        },id);
    }
}
